//
//  HUD.m
//  Molian
//
//  Created by 胡津 on 15/2/5.
//  Copyright (c) 2015年 xiaocan. All rights reserved.
//

#import "HUD.h"

@implementation HUD

-(UIView*)HUDImage :(UIImage*)image Title:(NSString*)title Content:(NSString*)content CANCEL:(NSString*)Cancel Confirm:(NSString*)confirm{
    
    toolbar=[[UIToolbar alloc]initWithFrame:[UIApplication sharedApplication].delegate.window.bounds];
    [toolbar setBarStyle:UIBarStyleBlack];
    toolbar.alpha=0;
    [[UIApplication sharedApplication].delegate.window addSubview:toolbar];
    
    [UIView animateWithDuration:0.2
                     animations:^{
                         toolbar.alpha=1;
                     }];
    
    View_screen=[[UIView alloc]init];
    View_screen.backgroundColor=[UIColor whiteColor];
    [View_screen.layer setCornerRadius:5];
    //View_screen.clipsToBounds = YES;
    [toolbar addSubview:View_screen];
    
    if (image==nil) {
        View_screen.frame=CGRectMake(20, (DeviceHeight-200)/2, DeviceWidth-40, 150);
    }else{
        View_screen.frame=CGRectMake(20, (DeviceHeight-200)/2, DeviceWidth-40, 160);
    }
    
    if (image) {
        UIImageView*Imageview_screen=[[UIImageView alloc]initWithFrame:CGRectMake(((DeviceWidth-40)-320)/2, -120, 320, 150)];
        Imageview_screen.image=image;
        [Imageview_screen setContentMode:UIViewContentModeScaleAspectFit];
        [View_screen addSubview:Imageview_screen];
    }

    

    UILabel*Label_screen=[[UILabel alloc]init];
    Label_screen.font=[UIFont fontWithName:FontName size:20];
    Label_screen.textColor=[UIColor blackColor];
    Label_screen.text=title;
    Label_screen.adjustsFontSizeToFitWidth = YES;
    Label_screen.textAlignment=NSTextAlignmentCenter;
    Label_screen.numberOfLines=2;
    [View_screen addSubview:Label_screen];
    Label_screen.frame=CGRectMake(0, View_screen.bounds.size.height-135, DeviceWidth-40, 30);

    if (content==nil){
        Label_screen.frame=CGRectMake(0, View_screen.bounds.size.height-135, DeviceWidth-40, 30);
    }
    
    UILabel*Label_screen2=[[UILabel alloc]initWithFrame:CGRectMake(10, View_screen.bounds.size.height-105, DeviceWidth-60, 55)];
    Label_screen2.font=[UIFont fontWithName:FontName size:15];
    Label_screen2.textColor=[UIColor grayColor];
    Label_screen2.text=content;
    Label_screen2.numberOfLines = 2;
    Label_screen2.textAlignment=NSTextAlignmentCenter;
    [View_screen addSubview:Label_screen2];
    

    BFPaperButton*btn_Confirm=[[BFPaperButton alloc]initWithFrame:CGRectMake((DeviceWidth-40)/2, View_screen.bounds.size.height-40, (DeviceWidth-40)/2, 40)raised:NO];
    [btn_Confirm addTarget:self action:@selector(btn_Confirm) forControlEvents:UIControlEventTouchUpInside];
    [btn_Confirm setTitle:confirm forState:UIControlStateNormal];
    [btn_Confirm setTitleColor:APPCOLOR(1) forState:UIControlStateNormal];
    [btn_Confirm setBackgroundColor:[UIColor whiteColor]];
//    btn_Confirm.usesSmartColor = YES;
    [View_screen addSubview:btn_Confirm];
    
    if (Cancel!=nil) {
        BFPaperButton*btn_Cancel=[[BFPaperButton alloc]initWithFrame:CGRectMake(0, View_screen.bounds.size.height-40, (DeviceWidth-40)/2, 40)raised:NO];
        [btn_Cancel setTitle:Cancel forState:UIControlStateNormal];
        [btn_Cancel addTarget:self action:@selector(btn_Cancel) forControlEvents:UIControlEventTouchUpInside];
        [btn_Cancel setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:1]];
        [btn_Cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        btn_Cancel.usesSmartColor = NO;
        [View_screen addSubview:btn_Cancel];
    }else{
        btn_Confirm.frame=CGRectMake(0, View_screen.bounds.size.height-40, View_screen.bounds.size.width, 40);
    }
    // 分隔线
    for (int i = 0; i < 2; i++) {
        UIView *Line = [[UIView alloc]initWithFrame:CGRectMake(0, View_screen.bounds.size.height-40, View_screen.bounds.size.width, 0.5)];
        Line.backgroundColor = RGBA(229, 229, 229, 1);
        if (i>=1) {
        Line.frame = CGRectMake((DeviceWidth-40)/2, View_screen.bounds.size.height-40, 0.5, 40);
        }
        [View_screen addSubview:Line];
    }
    return toolbar;
    
}

-(UIView*)HUDContent:(NSString*)content ToHeadImage:(NSURL*)url CANCEL:(NSString*)Cancel Confirm:(NSString*)confirm{
    
    toolbar=[[UIToolbar alloc]initWithFrame:[UIApplication sharedApplication].delegate.window.bounds];
    [toolbar setBarStyle:UIBarStyleBlack];
    toolbar.alpha=0;
    [[UIApplication sharedApplication].delegate.window addSubview:toolbar];
    
    [UIView animateWithDuration:0.2
                     animations:^{
                         toolbar.alpha=1;
                     }];
    
    View_screen=[[UIView alloc]init];
    View_screen.backgroundColor=[UIColor whiteColor];
    [View_screen.layer setCornerRadius:5];
    View_screen.clipsToBounds = YES;
    [toolbar addSubview:View_screen];
    View_screen.frame=CGRectMake(20, (DeviceHeight-200)/2, DeviceWidth-40, 230);

 
    
    UILabel*Label_screen2=[[UILabel alloc]initWithFrame:CGRectMake(10, View_screen.bounds.size.height-215, DeviceWidth-60, 75)];
    Label_screen2.font=[UIFont fontWithName:FontName size:15];
    Label_screen2.textColor=[UIColor grayColor];
    Label_screen2.text=content;
    Label_screen2.numberOfLines = 4;
    Label_screen2.textAlignment=NSTextAlignmentLeft;
    [View_screen addSubview:Label_screen2];
    
    
    UIImageView *mehead = [[UIImageView alloc]initWithFrame:CGRectMake((View_screen.bounds.size.width-170)/2, View_screen.bounds.size.height-120, 50, 50)];
    if (![MLUser currentUser].subAvatar || [[MLUser currentUser].subAvatar isEqualToString:@""]) {
        [mehead sd_setImageWithURL:[NSURL URLWithString:[MLUser currentUser].avatar.url] placeholderImage:[UIImage imageNamed:@"common_avatar_loading_background"]];
        
    }else{
        [mehead sd_setImageWithURL:[NSURL URLWithString:[MLUser currentUser].subAvatar] placeholderImage:[UIImage imageNamed:@"common_avatar_loading_background"]];
    }
   // [mehead sd_setImageWithURL:[NSURL URLWithString:[MLUser currentUser].avatar.url] placeholderImage:[UIImage imageWithColor:[UIColor whiteColor]]];
    mehead.layer.masksToBounds = YES;//开启圆角
    [mehead.layer setCornerRadius:4];
    [View_screen addSubview:mehead];
    
    UIImageView *arrow_icon = [[UIImageView alloc]initWithFrame:CGRectMake((View_screen.bounds.size.width-30)/2, View_screen.bounds.size.height-110, 30, 30)];
    arrow_icon.image = [UIImage imageNamed:@"home_personal_dialog-_arrow_icon"];
    [View_screen addSubview:arrow_icon];
    
    
    UIImageView *tohead = [[UIImageView alloc]initWithFrame:CGRectMake((View_screen.bounds.size.width+90)/2, View_screen.bounds.size.height-120, 50, 50)];
    tohead.layer.masksToBounds = YES;//开启圆角
    [tohead.layer setCornerRadius:4];
    [tohead sd_setImageWithURL:url placeholderImage:[UIImage imageWithColor:[UIColor whiteColor]]];
    [View_screen addSubview:tohead];
    

    
    BFPaperButton*btn_Confirm=[[BFPaperButton alloc]initWithFrame:CGRectMake((DeviceWidth-40)/2, View_screen.bounds.size.height-40, (DeviceWidth-40)/2, 40)raised:NO];
    [btn_Confirm addTarget:self action:@selector(btn_Confirm) forControlEvents:UIControlEventTouchUpInside];
    [btn_Confirm setTitle:confirm forState:UIControlStateNormal];
    [btn_Confirm setTitleColor:APPCOLOR(1) forState:UIControlStateNormal];
    [btn_Confirm setBackgroundColor:[UIColor whiteColor]];
    //    btn_Confirm.usesSmartColor = YES;
    [View_screen addSubview:btn_Confirm];
    
    if (Cancel!=nil) {
        BFPaperButton*btn_Cancel=[[BFPaperButton alloc]initWithFrame:CGRectMake(0, View_screen.bounds.size.height-40, (DeviceWidth-40)/2, 40)raised:NO];
        [btn_Cancel setTitle:Cancel forState:UIControlStateNormal];
        [btn_Cancel addTarget:self action:@selector(btn_Cancel) forControlEvents:UIControlEventTouchUpInside];
        [btn_Cancel setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:1]];
        [btn_Cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //        btn_Cancel.usesSmartColor = NO;
        [View_screen addSubview:btn_Cancel];
    }else{
        btn_Confirm.frame=CGRectMake(0, View_screen.bounds.size.height-40, View_screen.bounds.size.width, 40);
    }
    
    // 分隔线
    for (int i = 0; i < 2; i++) {
        UIView *Line = [[UIView alloc]initWithFrame:CGRectMake(0, View_screen.bounds.size.height-40, DeviceWidth, 0.5)];
        Line.backgroundColor = RGBA(229, 229, 229, 1);
        if (i>=1) {
            Line.frame = CGRectMake((DeviceWidth-40)/2, View_screen.bounds.size.height-40, 0.5, 40);
        }
        [View_screen addSubview:Line];
    }
    
    return toolbar;
    
}

-(UIView*)HUDEvaluationTitle:(NSString*)title CANCEL:(NSString*)Cancel Confirm:(NSString*)confirm{
    toolbar=[[UIToolbar alloc]initWithFrame:[UIApplication sharedApplication].delegate.window.bounds];
    [toolbar setBarStyle:UIBarStyleBlack];
    toolbar.alpha=0;
    [[UIApplication sharedApplication].delegate.window addSubview:toolbar];
    
    [UIView animateWithDuration:0.2
                     animations:^{
                         toolbar.alpha=1;
                     }];
    
    View_screen=[[UIView alloc]init];
    View_screen.backgroundColor=[UIColor whiteColor];
    [View_screen.layer setCornerRadius:5];
    View_screen.clipsToBounds = YES;
    [toolbar addSubview:View_screen];
    View_screen.frame=CGRectMake(20, (DeviceHeight-200)/2, DeviceWidth-40, 160);
    
    
    
    UILabel*Label_screen2=[[UILabel alloc]initWithFrame:CGRectMake(10, View_screen.bounds.size.height-165, DeviceWidth-60, 55)];
    Label_screen2.font=[UIFont fontWithName:FontName size:16];
    Label_screen2.textColor=[UIColor blackColor];
    Label_screen2.text=title;
    Label_screen2.numberOfLines = 2;
    Label_screen2.textAlignment=NSTextAlignmentCenter;
    [View_screen addSubview:Label_screen2];
    
    
    
    _ratingBar = [[RatingBar alloc] initWithFrame:CGRectMake(10, View_screen.bounds.size.height-110, DeviceWidth-60, 50)];
    [View_screen addSubview:_ratingBar];
    
    
    BFPaperButton*btn_Confirm=[[BFPaperButton alloc]initWithFrame:CGRectMake((DeviceWidth-40)/2, View_screen.bounds.size.height-40, (DeviceWidth-40)/2, 40)raised:NO];
    [btn_Confirm addTarget:self action:@selector(btn_Confirm) forControlEvents:UIControlEventTouchUpInside];
    [btn_Confirm setTitle:confirm forState:UIControlStateNormal];
    [btn_Confirm setTitleColor:APPCOLOR(1) forState:UIControlStateNormal];
    [btn_Confirm setBackgroundColor:[UIColor whiteColor]];
    //    btn_Confirm.usesSmartColor = YES;
    [View_screen addSubview:btn_Confirm];
    
    if (Cancel!=nil) {
        BFPaperButton*btn_Cancel=[[BFPaperButton alloc]initWithFrame:CGRectMake(0, View_screen.bounds.size.height-40, (DeviceWidth-40)/2, 40)raised:NO];
        [btn_Cancel setTitle:Cancel forState:UIControlStateNormal];
        [btn_Cancel addTarget:self action:@selector(btn_Cancel) forControlEvents:UIControlEventTouchUpInside];
        [btn_Cancel setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:1]];
        [btn_Cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //        btn_Cancel.usesSmartColor = NO;
        [View_screen addSubview:btn_Cancel];
    }else{
        btn_Confirm.frame=CGRectMake(0, View_screen.bounds.size.height-40, View_screen.bounds.size.width, 40);
    }
    
    // 分隔线
    for (int i = 0; i < 2; i++) {
        UIView *Line = [[UIView alloc]initWithFrame:CGRectMake(0, View_screen.bounds.size.height-40, DeviceWidth, 0.5)];
        Line.backgroundColor = RGBA(229, 229, 229, 1);
        if (i>=1) {
            Line.frame = CGRectMake((DeviceWidth-40)/2, View_screen.bounds.size.height-40, 0.5, 40);
        }
        [View_screen addSubview:Line];
    }
    
    return toolbar;
    
}

-(UIView*)HUDTitle:(NSString*)title TextStr:(NSString*)textstr CANCEL:(NSString*)Cancel Confirm:(NSString*)confirm{
    
    toolbar=[[UIToolbar alloc]initWithFrame:[UIApplication sharedApplication].delegate.window.bounds];
    [toolbar setBarStyle:UIBarStyleBlack];
    toolbar.alpha=0;
    [[UIApplication sharedApplication].delegate.window addSubview:toolbar];
    
    [UIView animateWithDuration:0.2
                     animations:^{
                         toolbar.alpha=1;
                     }];
    
    View_screen=[[UIView alloc]init];
    View_screen.backgroundColor=[UIColor whiteColor];
    [View_screen.layer setCornerRadius:5];
    View_screen.clipsToBounds = YES;
    [toolbar addSubview:View_screen];
    View_screen.frame=CGRectMake(20, (DeviceHeight-200)/2, DeviceWidth-40, 160);
    
    
    
    UILabel*Label_screen2=[[UILabel alloc]initWithFrame:CGRectMake(10, View_screen.bounds.size.height-165, DeviceWidth-60, 55)];
    Label_screen2.font=[UIFont fontWithName:FontName size:16];
    Label_screen2.textColor=[UIColor blackColor];
    Label_screen2.text=title;
    Label_screen2.numberOfLines = 2;
    Label_screen2.textAlignment=NSTextAlignmentCenter;
    [View_screen addSubview:Label_screen2];
    
    
    _textField = [[UITextField alloc]initWithFrame:CGRectMake(10, View_screen.bounds.size.height-110, DeviceWidth-60, 50)];
    _textField.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
    _textField.placeholder = [NSString stringWithFormat:@"   %@",textstr];
    _textField.font = [UIFont fontWithName:FontName size:13];
    [_textField.layer setBorderColor:[[UIColor grayColor] colorWithAlphaComponent:0.5].CGColor];
    [_textField.layer setBorderWidth:0.5];
    _textField.layer.masksToBounds = YES;//开启圆角
    [_textField.layer setCornerRadius:5];
    [View_screen addSubview:_textField];
    
    
    
    BFPaperButton*btn_Confirm=[[BFPaperButton alloc]initWithFrame:CGRectMake((DeviceWidth-40)/2, View_screen.bounds.size.height-40, (DeviceWidth-40)/2, 40)raised:NO];
    [btn_Confirm addTarget:self action:@selector(btn_Confirm) forControlEvents:UIControlEventTouchUpInside];
    [btn_Confirm setTitle:confirm forState:UIControlStateNormal];
    [btn_Confirm setTitleColor:APPCOLOR(1) forState:UIControlStateNormal];
    [btn_Confirm setBackgroundColor:[UIColor whiteColor]];
    //    btn_Confirm.usesSmartColor = YES;
    [View_screen addSubview:btn_Confirm];
    
    if (Cancel!=nil) {
        BFPaperButton*btn_Cancel=[[BFPaperButton alloc]initWithFrame:CGRectMake(0, View_screen.bounds.size.height-40, (DeviceWidth-40)/2, 40)raised:NO];
        [btn_Cancel setTitle:Cancel forState:UIControlStateNormal];
        [btn_Cancel addTarget:self action:@selector(btn_Cancel) forControlEvents:UIControlEventTouchUpInside];
        [btn_Cancel setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:1]];
        [btn_Cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //        btn_Cancel.usesSmartColor = NO;
        [View_screen addSubview:btn_Cancel];
    }else{
        btn_Confirm.frame=CGRectMake(0, View_screen.bounds.size.height-40, View_screen.bounds.size.width, 40);
    }
    
    // 分隔线
    for (int i = 0; i < 2; i++) {
        UIView *Line = [[UIView alloc]initWithFrame:CGRectMake(0, View_screen.bounds.size.height-40, DeviceWidth, 0.5)];
        Line.backgroundColor = RGBA(229, 229, 229, 1);
        if (i>=1) {
            Line.frame = CGRectMake((DeviceWidth-40)/2, View_screen.bounds.size.height-40, 0.5, 40);
        }
        [View_screen addSubview:Line];
    }
    
    return toolbar;
    
}



//提示框
+(void)Prompt:(NSString*)prompt
{
    CGSize size = [prompt sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:FontName size:14],NSFontAttributeName, nil]];
    CGFloat f = size.width;
    
    if (f>DeviceWidth - 50) {
        f = DeviceWidth - 50;
    }
    
    UILabel*Label_Prompt=[[UILabel alloc]initWithFrame:CGRectMake((DeviceWidth-(f+30))/2, (DeviceHeight-50)/2, f+30, 50)];
    Label_Prompt.text=prompt;
    Label_Prompt.numberOfLines = 0;
    Label_Prompt.font=[UIFont fontWithName:FontName size:14];
    Label_Prompt.textAlignment=NSTextAlignmentCenter;
    Label_Prompt.textColor=[UIColor whiteColor];
    Label_Prompt.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.7];
    Label_Prompt.layer.masksToBounds = YES;//开启圆角
    [Label_Prompt.layer setCornerRadius:7];
    [[UIApplication sharedApplication].delegate.window  addSubview:Label_Prompt];
    
    [Utils Hidden:Label_Prompt Bool:YES];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [Utils Hidden:Label_Prompt Bool:NO];
    });
   
    
}

-(void)btn_Cancel
{
    [self hide];
    if (self.Cancel) {
        self.Cancel();
    }
    
}

-(void)btn_Confirm
{
    [self hide];
    if (self.Confirm) {
        self.Confirm();
    }
}

+(void)shakeAnimationForView:(UIView *) view
{
    // 获取到当前的View
    CALayer *viewLayer = view.layer;
    // 获取当前View的位置
    CGPoint position = viewLayer.position;
    // 移动的两个终点位置
    CGPoint x = CGPointMake(position.x + 10, position.y);
    CGPoint y = CGPointMake(position.x - 10, position.y);
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];    // 设置动画
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];    // 设置运动形式
    [animation setFromValue:[NSValue valueWithCGPoint:x]];    // 设置开始位置
    [animation setToValue:[NSValue valueWithCGPoint:y]];    // 设置结束位置
    [animation setAutoreverses:YES];    // 设置自动反转
    [animation setDuration:.06];    // 设置时间
    [animation setRepeatCount:3];    // 设置次数
    [viewLayer addAnimation:animation forKey:nil];// 添加上动画
    
    
}

-(UIView*)Screening :(NSString*)Cancel Confirm:(NSString*)confirm{
    
    toolbar=[[UIToolbar alloc]initWithFrame:[UIApplication sharedApplication].delegate.window.bounds];
    [toolbar setBarStyle:UIBarStyleBlack];
    toolbar.alpha=0;
    [[UIApplication sharedApplication].delegate.window addSubview:toolbar];
    
    [UIView animateWithDuration:0.2
                     animations:^{
                         toolbar.alpha=1;
                     }];
    
    View_screen=[[UIView alloc]initWithFrame:CGRectMake(20, (DeviceHeight-300)/2, DeviceWidth-40, 300)];
    View_screen.backgroundColor=[UIColor whiteColor];
    View_screen.layer.masksToBounds = YES;//开启圆角
    [View_screen.layer setCornerRadius:10];
    [toolbar addSubview:View_screen];
    
    NSArray*arr=@[@"筛选",@"你想看到的恋人",@"恋人的身份"];
    
    for (int i=0; i<3; i++) {
        UILabel*Label_screen2=[[UILabel alloc]initWithFrame:CGRectMake(10, -20+70*i, DeviceWidth-60, 30)];
        Label_screen2.font=[UIFont fontWithName:FontName size:15];
        Label_screen2.textColor=[UIColor grayColor];
        Label_screen2.text=arr[i];
        Label_screen2.numberOfLines=0;
        Label_screen2.textAlignment=NSTextAlignmentLeft;
        if (i==0) {
            Label_screen2.frame=CGRectMake(0, 0, DeviceWidth-40, 40);
            Label_screen2.textAlignment=NSTextAlignmentCenter;
            Label_screen2.font=[UIFont fontWithName:FontName size:25];
        }
        [View_screen addSubview:Label_screen2];
        
    }
    
    SegmentedIdentitySex = [[NYSegmentedControl alloc] initWithItems:@[@"全部", @"男",@"女"]];
    SegmentedIdentitySex.titleTextColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    SegmentedIdentitySex.selectedTitleTextColor = [UIColor grayColor];
//    SegmentedIdentitySex.selectedTitleFont = [UIFont fontWithName:FontName size:15.0f];
    SegmentedIdentitySex.segmentIndicatorBackgroundColor = RGBA(227, 227, 227, 1);
    SegmentedIdentitySex.backgroundColor = [UIColor whiteColor];
    SegmentedIdentitySex.borderWidth = 0.25;
    SegmentedIdentitySex.segmentIndicatorBorderWidth = 0.0f;
    SegmentedIdentitySex.segmentIndicatorInset = 0.0f;
    SegmentedIdentitySex.segmentIndicatorBorderColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [SegmentedIdentitySex sizeToFit];
    //    [SegmentedIdentitySex addTarget:self action:@selector(segmentSelected) forControlEvents:UIControlEventValueChanged];
    SegmentedIdentitySex.cornerRadius = 2.f;
    SegmentedIdentitySex.frame=CGRectMake(10, 80, DeviceWidth-60, 40);
    SegmentedIdentitySex.selectedSegmentIndex=[[Utils defaultsForKey:@"IdentityGender"] integerValue];
    [View_screen addSubview:SegmentedIdentitySex];
    
    
    SegmentedIdentity = [[NYSegmentedControl alloc] initWithItems:@[@"全部",@"认证"]];
    SegmentedIdentity.titleTextColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    SegmentedIdentity.selectedTitleTextColor = [UIColor grayColor];
//    SegmentedIdentity.selectedTitleFont = [UIFont fontWithName:FontName size:15.0f];
    SegmentedIdentity.segmentIndicatorBackgroundColor = RGBA(227, 227, 227, 1);
    SegmentedIdentity.backgroundColor = [UIColor whiteColor];
    SegmentedIdentity.borderWidth = 0.25;
    SegmentedIdentity.segmentIndicatorBorderWidth = 0.0f;
    SegmentedIdentity.segmentIndicatorInset = 0.0f;
    SegmentedIdentity.segmentIndicatorBorderColor = [[UIColor redColor] colorWithAlphaComponent:0.5];
    [SegmentedIdentity sizeToFit];
    //    [SegmentedIdentitySex addTarget:self action:@selector(segmentSelected) forControlEvents:UIControlEventValueChanged];
    SegmentedIdentity.cornerRadius = 2.f;
    SegmentedIdentity.frame=CGRectMake(10, 150, DeviceWidth-60, 40);
    SegmentedIdentity.selectedSegmentIndex=[[Utils defaultsForKey:@"Identity"] integerValue];
    [View_screen addSubview:SegmentedIdentity];
    
    

    
    [self start];

    
    
    
    
    BFPaperButton*btn_Confirm=[[BFPaperButton alloc]initWithFrame:CGRectMake((DeviceWidth-40)-(((DeviceWidth-40)/2)-10), View_screen.bounds.size.height-50, ((DeviceWidth-40)/2)-20, 40)];
    [btn_Confirm addTarget:self action:@selector(btn_SegmentedConfirm) forControlEvents:UIControlEventTouchUpInside];
    [btn_Confirm setTitle:confirm forState:UIControlStateNormal];
    btn_Confirm.layer.masksToBounds = YES;//开启圆角
    [btn_Confirm.layer setCornerRadius:20];
    if ([Utils readArchiveData:APP_THEME_NAV_COLOR ForKey:@"Theskin.colo"]) {
        [btn_Confirm setBackgroundColor:[Utils readArchiveData:APP_THEME_NAV_COLOR ForKey:@"Theskin.colo"]];
    }else{
        [btn_Confirm setBackgroundColor:UIColorFromRGB(0xFE6A66)];
    }
    [View_screen addSubview:btn_Confirm];
    
    if (Cancel!=nil) {
        BFPaperButton*btn_Cancel=[[BFPaperButton alloc]initWithFrame:CGRectMake(10, View_screen.bounds.size.height-50, ((DeviceWidth-40)/2)-20, 40)];
        [btn_Cancel setTitle:Cancel forState:UIControlStateNormal];
        [btn_Cancel addTarget:self action:@selector(btn_Cancel) forControlEvents:UIControlEventTouchUpInside];
        [btn_Cancel setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.9]];
        [btn_Cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        if ([Utils readArchiveData:APP_THEME_NAV_COLOR ForKey:@"Theskin.colo"]) {
            [btn_Cancel.layer setBorderColor:[[Utils readArchiveData:APP_THEME_NAV_COLOR ForKey:@"Theskin.colo"] colorWithAlphaComponent:1].CGColor];
        }else{
            [btn_Cancel.layer setBorderColor:[UIColorFromRGB(0xFE6A66) colorWithAlphaComponent:1].CGColor];
        }
        [btn_Cancel.layer setBorderWidth:1];
        btn_Cancel.layer.masksToBounds = YES;//开启圆角
        [btn_Cancel.layer setCornerRadius:20];
        btn_Cancel.usesSmartColor = NO;
        [View_screen addSubview:btn_Cancel];
    }else{
        btn_Confirm.frame=CGRectMake(10, View_screen.bounds.size.height-50, (DeviceWidth-40)-20, 40);
    }
    
    return toolbar;
    
    
    
}




-(void)btn_SegmentedConfirm
{
    [Utils saveToDefaults:[NSString stringWithFormat:@"%lu",(unsigned long)SegmentedIdentity.selectedSegmentIndex] forKey:@"Identity"];
    [Utils saveToDefaults:[NSString stringWithFormat:@"%lu",(unsigned long)SegmentedIdentitySex.selectedSegmentIndex] forKey:@"IdentityGender"];
    [self hide];
    if (self.SegmentedConfirm) {
        self.SegmentedConfirm();
    }
    
}


-(void)hide
{
    [Utils animationSpringBounciness:20 View:View_screen Rect:CGRectMake(20, DeviceHeight+200, DeviceWidth-40, 200)];

    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:0.2
                         animations:^{
                             toolbar.alpha = 0;
                             dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                 [toolbar removeFromSuperview];
                             });
                         }];
    });

}

+ (HUD *)setOnViewWithTitle:(NSString *)title animated:(BOOL)animated{
    
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    HUD *hud = [[HUD alloc] initWithFrame:CGRectMake((DeviceWidth-60)/2, (DeviceHeight-60)/2, 60, 60)];
    
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake((-DeviceWidth/2)+30, (-DeviceHeight/2)+30, DeviceWidth, DeviceHeight)];
    view.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.2];
    [[UIApplication sharedApplication].delegate.window addSubview:view];

    
    UIToolbar*toolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(-20, -15, 100, 100)];
    [toolbar setBarStyle:UIBarStyleDefault];
    toolbar.alpha=0;
    [[UIApplication sharedApplication].delegate.window addSubview:toolbar];
    
    [UIView animateWithDuration:0.2
                     animations:^{
                         toolbar.alpha=1;
                     }];
    toolbar.layer.masksToBounds = YES;//开启圆角
    [toolbar.layer setCornerRadius:10];

    
    //You can add an image to the center of the spinner view
    //    UIImageView *img = [[UIImageView alloc] initWithFrame:GMD_SPINNER_IMAGE];
    //    img.image = GMD_IMAGE;
    //    hud.center = img.center;
    //    [hud addSubview:img];
    
    if (title) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(-70.0f, 50.0f, 200.0f, 42.0f)];
        label.font = [UIFont boldSystemFontOfSize:14.0f];
        label.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = title;
        [hud addSubview:label];
    }
 
//    [hud addSubview:toolbar];
    [hud insertSubview:toolbar atIndex:0];
    [hud insertSubview:view atIndex:0];

    [hud start];
    [[UIApplication sharedApplication].delegate.window addSubview:hud];
    
//    float height = [[UIScreen mainScreen] bounds].size.height;
//    float width = [[UIScreen mainScreen] bounds].size.width;
//    CGPoint center = CGPointMake(width/2, height/2);
//    hud.center = center;
    return hud;
}

//------------------------------------
// Hide the leader in view
//------------------------------------
+ (BOOL)hideFromViewAnimated:(BOOL)animated {
    HUD *hud = [HUD HUDForView:[UIApplication sharedApplication].delegate.window];
    [hud stop];
    if (hud) {
//        [[UIApplication sharedApplication].delegate.window setUserInteractionEnabled:YES];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        [hud removeFromSuperview];
        return YES;
    }
    return NO;
}

//------------------------------------
// Perform search for loader and hide it
//------------------------------------
+ (HUD *)HUDForView: (UIView *)view {
    HUD *hud = nil;
    NSArray *subViewsArray = view.subviews;
    Class hudClass = [HUD class];
    for (UIView *aView in subViewsArray) {
        if ([aView isKindOfClass:hudClass]) {
            hud = (HUD *)aView;
        }
    }
    return hud;
}



#pragma mark - Initialization
- (instancetype)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        [self setup];
    }
    return self;
}

#pragma mark - Setup
- (void)setup {
    self.backgroundColor = [UIColor clearColor];
    
    //---------------------------
    // Set line width
    //---------------------------
    _lineWidth = GMD_SPINNER_LINE_WIDTH;
    
    //---------------------------
    // Round Progress View
    //---------------------------
    self.backgroundLayer = [CAShapeLayer layer];
    _backgroundLayer.strokeColor = APPCOLOR(1).CGColor;
    _backgroundLayer.fillColor = self.backgroundColor.CGColor;
    _backgroundLayer.lineCap = kCALineCapRound;
    _backgroundLayer.lineWidth = _lineWidth;
    [self.layer addSublayer:_backgroundLayer];
    
    
}

- (void)drawRect:(CGRect)rect {
    //-------------------------
    // Make sure layers cover the whole view
    //-------------------------
    _backgroundLayer.frame = self.bounds;
}

#pragma mark - Drawing

- (void)drawBackgroundCircle:(BOOL) partial {
    CGFloat startAngle = - ((float)M_PI / 2); // 90 Degrees
    CGFloat endAngle = (32 * (float)M_PI) + startAngle;
    CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
    CGFloat radius = (self.bounds.size.width - _lineWidth)/2;
    
    //----------------------
    // Begin draw background
    //----------------------
    
    UIBezierPath *processBackgroundPath = [UIBezierPath bezierPath];
    processBackgroundPath.lineWidth = _lineWidth;
    
    //---------------------------------------
    // Make end angle to 90% of the progress
    //---------------------------------------
    if (partial) {
        endAngle = (1.8f * (float)M_PI) + startAngle;
    }
    [processBackgroundPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
    _backgroundLayer.path = processBackgroundPath.CGPath;
}

#pragma mark - Spin
- (void)start {
//    self.isSpinning = YES;
    [self drawBackgroundCircle:YES];
    
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
    rotationAnimation.duration = 1;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = HUGE_VALF;
    [_backgroundLayer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

- (void)stop{
    [self drawBackgroundCircle:NO];
    [_backgroundLayer removeAllAnimations];
//    self.isSpinning = NO;
}

-(UIView*)TheskinChoose:(UIViewController*)vc
{
    toolbar=[[UIToolbar alloc]initWithFrame:[UIApplication sharedApplication].delegate.window.bounds];
    [toolbar setBarStyle:UIBarStyleBlack];
    toolbar.alpha=0;
    [vc.view addSubview:toolbar];
    
    vc.navigationItem.rightBarButtonItem.enabled = NO;
    vc.navigationItem.leftBarButtonItem.enabled = NO;

    [UIView animateWithDuration:0.2
                     animations:^{
                         toolbar.alpha=1;
                     }];
    
    vcController=vc;
    View_chest=[[UIView alloc]initWithFrame:CGRectMake(0, DeviceHeight, DeviceWidth, (DeviceWidth/10)+190)];
    View_chest.backgroundColor = [UIColor whiteColor];
    [vc.view addSubview:View_chest];
    
    NSArray*colorArr=@[UIColorFromRGB(0xFE6A66),[UIColor paperColorAmber], [UIColor paperColorDeepPurple800],[UIColor paperColorGreen400],[UIColor paperColorRed900],[UIColor paperColorLightBlue500],[UIColor paperColorLightGreen600],[UIColor paperColorBrown600],[UIColor paperColorOrange900],[UIColor paperColorPurple800],[UIColor paperColorTeal500],[UIColor paperColorPinkA400],[UIColor paperColorTeal200],[UIColor paperColorRed600],[UIColor paperColorPurple600]];
    
    [Utils animationSpringBounciness:20 View:View_chest Rect:CGRectMake(0, DeviceHeight-((DeviceWidth/10)+190), DeviceWidth, (DeviceWidth/10)+190)];

    for (int i=0; i<colorArr.count; i++) {
        int x = i % 5;  // 列数
        int y = i / 5;  // 行数
        UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake((DeviceWidth/25)*(1+5*x), 10+(10+DeviceWidth/10)*y, (DeviceWidth/10), (DeviceWidth/10))];
        btn.backgroundColor=colorArr[i];
        [btn addTarget:self action:@selector(chest:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag=i;
        [View_chest addSubview:btn];
    }
    return toolbar;
}

-(void)chest:(UIButton*)sender
{

    [Utils animationSpringBounciness:20 View:View_chest Rect:CGRectMake(0, DeviceHeight, DeviceWidth, (DeviceWidth/10)+190)];

    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [View_chest removeFromSuperview];
        [UIView animateWithDuration:0.2
                         animations:^{
                             toolbar.alpha = 0;
                             dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                 [toolbar removeFromSuperview];
                             });
                         }];
    });
    [Utils Theskin:(int)sender.tag Vc:vcController];
    vcController.navigationItem.rightBarButtonItem.enabled = YES;
    vcController.navigationItem.leftBarButtonItem.enabled = YES;

}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
